package cl.thesouthfun.mantenedor.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import cl.thesouthfun.mantenedor.R;
import cl.thesouthfun.mantenedor.vo.Pasajero;

public class AdapterPasajero extends ArrayAdapter<Pasajero> {

	private ArrayList<Pasajero> items;
	
	public AdapterPasajero(Context context, int textViewResourceId, ArrayList<Pasajero> items) {
		super(context, textViewResourceId, textViewResourceId, items);
		this.items = items;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = convertView;
		if (view == null) {
			LayoutInflater layoutInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			view = layoutInflater.inflate(R.layout.row_pasajero, null);
		}
		Pasajero pasajero = items.get(position);
		if (pasajero != null) {
			TextView lblRut = (TextView)view.findViewById(R.id.toptext);
			TextView lblNombre = (TextView)view.findViewById(R.id.bottomtext);
			
			if(lblRut != null){
				lblRut.setText(pasajero.getRut());
			}
			if(lblNombre != null){
				lblNombre.setText(pasajero.getNombre() + " " +
						pasajero.getApellidoPaterno() + " " +
						pasajero.getApellidoMaterno());
			}
		}
		return view;
	}

}
